package edgeTSQL

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEntity"
	"time"
)

func InsertRecord(entity commEntity.IEntity) error {
	// 精度到小时的格式：年月日时
	tblName := tableName + "_" + time.Now().Format("2006010215")

	// 写入时间
	now := time.Now().UnixMilli()
	entity.GetBaseEntity().CreateTime = now
	entity.GetBaseEntity().UpdateTime = now

	// 构造SQL语句
	sql, values, err := SQL.InsertRecord(tblName, entity)
	if err != nil {
		return err
	}

	// 执行SQL语句
	id, err := API.InsertRecord(tblName, sql, values)
	if err != nil {
		return err
	}

	// 写入基础信息
	baseEntity := entity.GetBaseEntity()
	baseEntity.Id = id
	return nil
}
